import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import java.io.File

/**
 *  @AUTHOR zhangxiaofan07
 *  @CREATE 2022-03-01 17:04
 */

@Composable
fun LazyScrollable(dirStr: String, size: Int, fileList: List<File>) {
    Box(modifier = Modifier.height(200.dp).width(2000.dp).border(1.dp, Color.Black)) {
        val state = rememberLazyListState()

        LazyColumn(Modifier.padding(end = 12.dp), state) {
            item {
                Text(if (dirStr == "") "" else "选择的路径：$dirStr")
            }

            items(size) { x ->
                Text("第${x + 1}个文件: ${fileList[x].name}")
                Spacer(modifier = Modifier.height(5.dp))
            }
        }
        VerticalScrollbar(
            modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
            adapter = rememberScrollbarAdapter(
                scrollState = state
            )
        )
    }
}

